package com.ruoyi.communal.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.communal.domain.CommonProblem;
import com.ruoyi.communal.service.ICommonProblemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 常见问题Controller
 * 
 * @author ruoyi
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/communal/problem")
public class CommonProblemController extends BaseController
{
    @Resource
    private ICommonProblemService commonProblemService;

    /**
     * 查询常见问题列表
     */
    @PreAuthorize("@ss.hasPermi('communal:problem:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommonProblem commonProblem)
    {
        startPage();
        List<CommonProblem> list = commonProblemService.selectCommonProblemList(commonProblem);
        return getDataTable(list);
    }

    /**
     * 导出常见问题列表
     */
    @PreAuthorize("@ss.hasPermi('communal:problem:export')")
    @Log(title = "常见问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommonProblem commonProblem)
    {
        List<CommonProblem> list = commonProblemService.selectCommonProblemList(commonProblem);
        ExcelUtil<CommonProblem> util = new ExcelUtil<CommonProblem>(CommonProblem.class);
        util.exportExcel(response, list, "常见问题数据");
    }

    /**
     * 获取常见问题详细信息
     */
    @PreAuthorize("@ss.hasPermi('communal:problem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(commonProblemService.selectCommonProblemById(id));
    }

    /**
     * 新增常见问题
     */
    @PreAuthorize("@ss.hasPermi('communal:problem:add')")
    @Log(title = "常见问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommonProblem commonProblem)
    {
        return toAjax(commonProblemService.insertCommonProblem(commonProblem));
    }

    /**
     * 修改常见问题
     */
    @PreAuthorize("@ss.hasPermi('communal:problem:edit')")
    @Log(title = "常见问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommonProblem commonProblem)
    {
        return toAjax(commonProblemService.updateCommonProblem(commonProblem));
    }

    /**
     * 删除常见问题
     */
    @PreAuthorize("@ss.hasPermi('communal:problem:remove')")
    @Log(title = "常见问题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(commonProblemService.deleteCommonProblemByIds(ids));
    }
}
